package com.yike.user.service.impl;

import com.yike.user.entity.CommissionSettle;
import com.yike.user.mapper.CommissionSettleMapper;
import com.yike.user.service.CommissionSettleService;
import com.yike.user.param.CommissionSettlePageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 代理商分佣结算表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-09
 */
@Slf4j
@Service
public class CommissionSettleServiceImpl extends BaseServiceImpl<CommissionSettleMapper, CommissionSettle> implements CommissionSettleService {

    @Autowired
    private CommissionSettleMapper commissionSettleMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveCommissionSettle(CommissionSettle commissionSettle) throws Exception {
        return super.save(commissionSettle);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCommissionSettle(CommissionSettle commissionSettle) throws Exception {
        return super.updateById(commissionSettle);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteCommissionSettle(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<CommissionSettle> getCommissionSettlePageList(CommissionSettlePageParam commissionSettlePageParam) throws Exception {
        Page<CommissionSettle> page = new PageInfo<>(commissionSettlePageParam, OrderItem.desc(getLambdaColumn(CommissionSettle::getCreateTime)));
        LambdaQueryWrapper<CommissionSettle> wrapper = new LambdaQueryWrapper<>();
        IPage<CommissionSettle> iPage = commissionSettleMapper.selectPage(page, wrapper);
        return new Paging<CommissionSettle>(iPage);
    }

}
